/*
 *   Copyright (C) 2007 by Andrzej Oczkowicz
 *   andrew_lz@poczta.fm
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *   KMediaCatalog :)
 *
 */

#include <QObject>
#include <QImage>

#include "kutils.h"
#include "kinfo.h"

namespace kUtils{

QString & path(QString&path){
  if ( path.right( 1 ) != QDir::separator()  )
    path.append( QDir::separator() );
  return path;
}

bool appQuery( const QString & text )
{
  return ( QMessageBox::question(QApplication::activeWindow(), QString(APP_TITLE": "+ QObject::tr("Question...")), text, QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) ;
}

void appMsg(const QString & text, const QString & caption)
{
    if (caption.isEmpty())
      QMessageBox::information(QApplication::activeWindow(), QString(APP_TITLE": "+ QObject::tr("Information")), text);
    else
      QMessageBox::information(QApplication::activeWindow(), caption, text);
}


void makeTopPicture(QFrame*frame, const QString &text, const QString &right_image)
{
    QHBoxLayout *hboxLayout;
    QLabel *labelLeft;
    QLabel *labelTitle;
    QLabel *labelRight;
    frame->setObjectName(QString::fromUtf8("frame"));
    QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(0));
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(frame->sizePolicy().hasHeightForWidth());
    frame->setSizePolicy(sizePolicy);
    frame->setMinimumSize(QSize(300, 40));
    frame->setMaximumSize(QSize(16777215, 40));
    frame->setFrameShape(QFrame::StyledPanel);
    frame->setFrameShadow(QFrame::Raised);
    hboxLayout = new QHBoxLayout(frame);
    hboxLayout->setSpacing(0);
    hboxLayout->setMargin(0);
    hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    labelLeft = new QLabel(frame);
    labelLeft->setObjectName(QString::fromUtf8("labelLeft"));
    QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
    sizePolicy1.setHorizontalStretch(0);
    sizePolicy1.setVerticalStretch(0);
    sizePolicy1.setHeightForWidth(labelLeft->sizePolicy().hasHeightForWidth());
    labelLeft->setSizePolicy(sizePolicy1);
    labelLeft->setMinimumSize(QSize(100, 35));
    labelLeft->setPixmap(resLoader::loadImage("left_all.png"));

    hboxLayout->addWidget(labelLeft);

    labelTitle = new QLabel(frame);
    labelTitle->setObjectName( QString::fromUtf8("labelTitle") );
    labelTitle->setText(text);

    QPalette palette;
    palette.setColor( QPalette::Window, QColor(143, 148, 255) );
    palette.setColor( QPalette::WindowText, QColor(255, 255, 255) );
    labelTitle->setAutoFillBackground(true);
    labelTitle->setPalette(palette);

    frame->setAutoFillBackground(true);
    frame->setPalette(palette);

    hboxLayout->addWidget(labelTitle);

    labelRight = new QLabel(frame);
    labelRight->setObjectName(QString::fromUtf8("labelRight"));
    QSizePolicy sizePolicy2(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
    sizePolicy2.setHorizontalStretch(0);
    sizePolicy2.setVerticalStretch(0);
    sizePolicy2.setHeightForWidth(labelRight->sizePolicy().hasHeightForWidth());
    labelRight->setSizePolicy(sizePolicy2);
    labelRight->setPixmap( resLoader::loadImage(right_image) );
    labelRight->setMargin(0);

    hboxLayout->addWidget(labelRight);
    QSize size(318, 58);
    size = size.expandedTo(frame->minimumSizeHint());
    frame->resize(size);
}

}

QPixmap resLoader::loadImage(const QString & name)
{
  return QPixmap( ":/images/" + name );
}
